/**
 * This file was created by the SockFullOfOranges group for use in SpaceTrader
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JButton;

/**
 * This class creates the option screen to be used in the GUI
 * @author Andrew Darrohn, Nick Popescu
 * @version 1.0
 */
public class OptionsScreen extends JPanel implements ActionListener {

    /**
     * This represents the "Save Game" button
     */
    private final JButton saveGame;
    
    /**
     * This represents the "Load Game" button
     */
    private final JButton loadGame;

    /**
     * this method creates the panel used in the GUI.
     */
    public OptionsScreen() { // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.constructorsOnlyInvokeFinalMethods
	setLayout(null);
	setOpaque(false);

	saveGame = new JButton("Save Game");
	saveGame.setBounds(85, 60, 120, 25); // $codepro.audit.disable numericLiterals
	saveGame.addActionListener(this);
	add(saveGame);

	loadGame = new JButton("Load Game");
	loadGame.setBounds(85, 85, 120, 25); // $codepro.audit.disable numericLiterals
	loadGame.addActionListener(this);
	add(loadGame);
    }

    /**
     * This method saves or loads the data depending on which button was clicked 
     * @param e The ActionEven of clicking buttons 
     */
    @Override
    public void actionPerformed(ActionEvent e) {
	if (e.getSource().equals(saveGame)) {
	    final SaveLoad save = new SaveLoad();
	    save.save(Game.SaveFilename);
	    System.out.println("Saved!");
	}

	if (e.getSource().equals(loadGame)) {
	    System.out.println("Clicked Load Game");

	    final SaveLoad load = new SaveLoad();
	    final SaveLoad loadData = SaveLoad.load(Game.SaveFilename);

	    if (loadData != null) {
		Game.Space = loadData.space; // $codepro.audit.disable assignmentToNonFinalStatic
		Game.Player = loadData.player; // $codepro.audit.disable assignmentToNonFinalStatic

		System.out.println(Game.Player);
		System.out.println(Game.Player.getName());
		System.out.println(Game.Player.getShip().getName());

		Game.InitConfigScreen
			.showScreen(Game.GameScreen = new GameScreen( // $codepro.audit.disable assignmentToNonFinalStatic
				Game.Space, Game.Player));
	    }

	}
    }
}
